﻿package pl.kozulowski.loaders {
	
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	
	public class XmlLoader extends EventDispatcher {
		
		private var _req:URLRequest;
		private var _ldr:URLLoader;
		private var _url:String;
		private var _xml:XML;
		
		public function XmlLoader() {}
		
		public function load($url:String):void {
			_url = $url;
			_req = new URLRequest(_url);
			_ldr = new URLLoader();
			_ldr.addEventListener(Event.COMPLETE, onLoaded);
			_ldr.load(_req);
		}
		
		private function onLoaded($e:Event):void {
			_xml = new XML($e.target.data);
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public function get xml():XML {
			return _xml;
		}
		
	}
	
}